package com.skymxc.demo.explorer;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;

import com.skymxc.demo.explorer.fragment.SettingFragment;

/**
 * Created by sky-mxc
 */
public class SettingActivity extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_setting);
        if (savedInstanceState==null ) {
            getFragmentManager().beginTransaction()
                    .add(R.id.root, new SettingFragment(), "setting")
                    .commit();
        }

    }

    public void changeTheme(int theme){
        switch (theme){
            case 0:
                //白色
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                break;
            case 1:
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                break;
        }
        recreate();
    }

    /**
     * 启动设置Activity
     * @param mainActivity
     * @param requestSetting
     */
    public static void startActivityForResult(MainActivity mainActivity, int requestSetting) {
        Intent in = new Intent(mainActivity,SettingActivity.class);
        mainActivity.startActivityForResult(in,requestSetting);
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        outState.putBoolean("recreate",true);
    }
}
